function cmsUploadImg(btnSelectImg, imgFile, imgPreviews, imgUrls, imageFlag) {

    var $btnSelectImg = $('#' + btnSelectImg);
    var $imgFile = $('#' + imgFile);
    $btnSelectImg.click(function () {
        if(typeof FileReader==='undefined'){
            $imgFile.attr('disabled','disabled');
            bootbox.alert("抱歉，你的浏览器不支持 FileReader,建议使用google浏览器");
        }else{
            $imgFile.trigger("click")
        }
    });
    $imgFile.change(function(){
        uploadComm(imgFile,imgPreviews,imgUrls,imageFlag);
        // uploadComm(imgFile,["imgPreview"],["imgUrl"],"product_main");
    });
}

function uploadComm(fileId, imgId, inputId, imageFlag,callback) {
    if(!$.trim(imageFlag)) {
        imageFlag = "product_main";
    }
    var fd = new FormData();
    var files = document.getElementById(fileId).files;
    var len = files.length;
    for(var i = 0; i < len; i++) {
        var reader = new FileReader();
        reader.readAsDataURL(files[i]);
        fd.append(i, files[i]);
    }
    $.ajax({
        url: '/uploadImg',
        type: 'post',
        data: fd,
        processData: false,
        contentType: false,
        beforeSend: function(request) {
            request.setRequestHeader("fileFlag", imageFlag);
        },
        success: function(data) {
            if('0000' == data.code) {
                var res = data.data;
                for(var i = 0; i < res.list.length; i++) {
                    var url = res.httpUrl + res.list[i];
                    $("#" + imgId[i]).attr("src", url);
                    $("#" + inputId[i]).val(res.list[i]);
                }
            } else {
                var msg = data.msg;
                bootbox.alert("上传失败：" + msg);
            }
        }
    });
}